package com.pbking.facebook.delegates.feed
{
	import com.pbking.facebook.Facebook;
	import com.pbking.facebook.data.feed.TemplateBundle;
	import com.pbking.facebook.delegates.FacebookDelegate;

	/**
	 * @author sol wu
	 * @see http://wiki.developers.facebook.com/index.php/Feed.registerTemplateBundle
	 */
	public class RegisterTemplateBundleDelegate extends FacebookDelegate
	{
		/** 
		 * the return value is an integer.  Spec does not say if it is 4bytes or 8bytes.  
		 * however, testing showed that it could be larger than maximum value of int.  Therfore, this is a Number, not int.
		 */
		public var templateBundleId:Number;
		
		private var facebook:Facebook;
		
		/**
		 * 
		 */
		public function RegisterTemplateBundleDelegate(facebook:Facebook, bundle:TemplateBundle)
		{
			super(facebook);
			if (bundle.one_line_story_templates.length > 0) { fbCall.setRequestArgument("one_line_story_templates", bundle.one_line_story_templates_JSON); }
			if (bundle.short_story_templates.length > 0) { fbCall.setRequestArgument("short_story_templates", bundle.short_story_templates_JSON); }
			if (bundle.full_story_template != null) { fbCall.setRequestArgument("full_story_template", bundle.full_story_template_JSON); }
						
			fbCall.post("facebook.feed.registerTemplateBundle");
		}

		override protected function handleResult(result:Object):void
		{
			if (result is Number) {
				templateBundleId = result as Number;
			} else if (result is int) {
				templateBundleId = result as int;
			}
		}

	}
}